package cn.wawi.dao;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Component;

@Component("dao")
public class DaoSupport{

	@Resource
	SqlSessionTemplate sqlSessionTemplate;
	
	public <T> List<T> findAll(String mapperName,Map<String, Object> map) {
		return sqlSessionTemplate.selectList(mapperName+".findAll",map);
	}

	public <T> T findOne(String mapperName,Object t) {
		return sqlSessionTemplate.selectOne(mapperName+".findOne",t);
	}
	public void saveOne(String mapperName,Object t) {
	    sqlSessionTemplate.insert(mapperName+".saveOne",t);
	}
	public int deleteOne(String mapperName,String id) {
		return sqlSessionTemplate.delete(mapperName+".deleteOne",id);
	}
	public int updateOne(String mapperName,Object t) {
		return sqlSessionTemplate.update(mapperName+".updateOne",t);
	}
	public int deleteBatch(String mapperName,String[] ids) {
		return sqlSessionTemplate.delete(mapperName+".deleteBatch",ids);
	}
	public int updateBatch(String mapperName,String[] ids){
		return sqlSessionTemplate.delete(mapperName+".updateBatch",ids);
	}
}
